<template>
	<view>
		<view style="">
			<u-search inputAlign="center" placeholder="司机姓名/手机号" @search="data=[];form.page=1;getData()"
				@click="data=[];getData()" v-model="form.text" :showAction="false"></u-search>
		</view>
		<view v-if="data">
			<u-cell-group>
				<u-cell-item v-for="item in data" @click="selectItem=item;show=true" :title="item.employe_name" :value="item.employe_tel">
				</u-cell-item>
			</u-cell-group>
		</view>
		<u-modal v-model="show" @confirm="replaceEmploye">
			<view class="slot-content" style="padding: 30rpx;">
				<text>确定将 【</text>
				<text>{{orders.employe_name}} 】/</text>
				<text>替换成 【</text>
				<text>{{selectItem.employe_name}} 】</text>
				<text>吗？ </text>
			</view>
		</u-modal>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selectItem: null,
				show: false,
				data: null,
				orders: null,
				form: {
					text: '',

				}
			}
		},
		mounted() {
			this.getData();
		},
		onLoad(options) {
			if (options.data) {
				this.orders = JSON.parse(decodeURIComponent(options.data));
			}
		},
		onPullDownRefresh() {
			this.refresherpulling();
		},
		onReachBottom() {
			console.log(this.count);
			if (this.count == 0) {
				this.$refs.uToast.show({
					title: '没那么多代驾员了',
					type: "warning"
				});
				return;
			}
			this.scrolltolower();
		},
		methods: {
			replaceEmploye() {
				var that = this;
				var form = {};
				form.before_employe_id=this.selectItem.employe_id;
				form.before_employe_name=this.selectItem.employe_name;
				form.before_employe_tel=this.selectItem.employe_tel;
				form.order_id = this.orders.orders_id;
				that.$http.post('/orders/replaceEmploye',form, (res) => {
					if (res.data.success) {
						that.data = res.data.result.list;
						that.$refs.uToast.show({
							title: '更换成功',
							type: "success"
						});
						uni.$emit("getOrdersInfo", that.data);
						uni.navigateBack();
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			getData() {
				var that = this;
				that.$http.post('/employe/ListByEntity', this.form, (res) => {
					if (res.data.success) {
						that.data = res.data.result.list;
					} else {
						that.refs.myModal.show('请求失败', res.data.result.message);
					}
				});
			},
			refresherpulling(e) {
				this.form.page = 1;
				this.refresher = true;
				this.data = [];
				this.getData();
			},
			scrolltolower(e) {
				this.form.page++;
				this.getData();
			},
		}
	}
</script>

<style>

</style>